<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册 - 会议管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 1rem;
        }

        .register-form {
            background-color: white;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
        }

        .form-title {
            text-align: center;
            color: #2d3748;
            margin-bottom: 2rem;
            font-size: 1.5rem;
            font-weight: 600;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            color: #4a5568;
        }

        .form-group input {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid #e2e8f0;
            border-radius: 4px;
            font-size: 1rem;
        }

        .radio-group {
            display: flex;
            gap: 1rem;
            margin-top: 0.5rem;
        }

        .radio-option {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .radio-option input[type="radio"] {
            width: auto;
        }

        .button-group {
            display: flex;
            gap: 1rem;
            margin-top: 2rem;
        }

        .btn {
            padding: 0.8rem 1.5rem;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-size: 1rem;
            border: none;
            width: 100%;
        }

        .btn-primary {
            background-color: #4299e1;
            color: white;
            width: 65%;
        }

        .btn-secondary {
            background-color: #e2e8f0;
            color: #4a5568;
            width: 35%;
        }

        .btn:hover {
            opacity: 0.9;
        }

        .toast {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 1rem 2rem;
            color: white;
            border-radius: 4px;
            display: none;
            z-index: 1001;
            font-size: 14px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        }

        .toast.success {
            background-color: #48bb78;
        }

        .toast.error {
            background-color: #f56565;
        }

        .toast.show {
            display: block;
            animation: fadeInOut 3s ease;
        }

        @keyframes fadeInOut {
            0% { opacity: 0; transform: translateY(-20px); }
            10% { opacity: 1; transform: translateY(0); }
            90% { opacity: 1; transform: translateY(0); }
            100% { opacity: 0; transform: translateY(-20px); }
        }
    </style>
</head>
<body>
    <div class="register-form">
        <h1 class="form-title">用户注册</h1>
        <form id="registerForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="user_name" required>
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required>
            </div>
            <div class="form-group">
                <label>用户类别</label>
                <div class="radio-group">
                    <label class="radio-option">
                        <input type="radio" name="adminFlag" value="false" checked>
                        普通用户
                    </label>
                    <label class="radio-option">
                        <input type="radio" name="adminFlag" value="true">
                        管理员
                    </label>
                </div>
            </div>
            <div class="button-group">
                <button type="submit" class="btn btn-primary">注册</button>
                <button type="button" class="btn btn-secondary" onclick="window.location.href='login.html'">返回登录</button>
            </div>
        </form>
    </div>

    <!-- 提示消息 -->
    <div class="toast" id="toast"></div>

    <script>
        // 显示提示消息
        function showToast(message, type = 'success') {
            const toast = document.getElementById('toast');
            toast.textContent = message;
            toast.className = 'toast ' + type;
            toast.classList.add('show');
            setTimeout(() => {
                toast.classList.remove('show');
            }, 3000);
        }

        // 处理注册表单提交
        document.getElementById('registerForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const formData = {
                user_name: document.getElementById('username').value,
                password: document.getElementById('password').value,
                adminFlag: document.querySelector('input[name="adminFlag"]:checked').value === 'true'
            };

            try {
                const response = await fetch('/user/register', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(formData)
                });

                const data = await response.json();
                if (data.state === 200) {
                    showToast('注册成功！正在登录...', 'success');
                    // 存储用户信息
                    localStorage.setItem('user', JSON.stringify({
                        user_name: formData.user_name,
                        adminFlag: formData.adminFlag
                    }));
                    // 延迟跳转，让用户看到成功提示
                    setTimeout(() => {
                        window.location.href = 'main.html';
                    }, 1500);
                } else {
                    showToast('注册失败：' + (data.msg || '请稍后重试'), 'error');
                }
            } catch (error) {
                console.error('Registration failed:', error);
                showToast('注册失败：网络错误，请稍后重试', 'error');
            }
        });
    </script>
</body>
</html> 